﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Utility;
using System.Runtime.Serialization;

namespace Classes
{
    [DataContract(IsReference = true)]
    public class Worker
    {
        #region Variables
        [DataMember]
        int id = UniqueID.Worker;
        #endregion

        #region Properties
        public int ID
        {
            get
            {
                return id;
            }
        }

        [DataMember]
        public Department Department
        {
            get;
            set;
        }

        [DataMember]
        public Office Office
        {
            get;
            set;
        }

        [DataMember]
        public TelephonePost TelephonePost
        {
            get;
            set;
        }

        [DataMember]
        public string Name
        {
            get;
            set;
        }

        [DataMember]
        public Project CurrentProject
        {
            get;
            set;
        }

        [DataMember]
        public JobEntry CurrentJob
        {
            get;
            set;
        }

        [DataMember]
        public List<JobEntry> JobHistory;
        #endregion

        public struct JobEntry
        {
            public JobEntry(string position, float payment, string hiredate)
            {
                this.Position = position;
                this.Payment = payment;
                this.HireDate = hiredate;
            }

            public string Position;
            public float Payment;
            public string HireDate;
        }

        /// <summary>
        /// Only used in serialization/ deserialization.
        /// </summary>
        public Worker() { }

        public void UnassignWorker()
        {
            JobHistory.Add(new Worker.JobEntry(CurrentJob.Position,
                                CurrentJob.Payment, CurrentJob.HireDate));
            CurrentJob = new Worker.JobEntry();

            if (Department != null) Department.Workers.Remove(this);
            CurrentProject = null;
            Office = null;
            Department = null;

            TelephonePost = null;
        }
    }
}
